<template>
  <el-header class="admin-header">
    <div class="admin-user-info">
      当前登录：
      <template v-if="isLoggedIn">
        <router-link to="/manage/info" class="username">{{ username }}</router-link>
      </template>
      <span v-else class="login-tip">未登录</span>
    </div>
  </el-header>
</template>

<script>
export default {
  name: 'ManageHeader',
  data() {
    return {
      isLoggedIn: false,
      username: '',
    }
  },
  mounted() {
    this.checkLoginStatus();
  },
  methods: {
    checkLoginStatus() {
      this.isLoggedIn = !!localStorage.getItem('token');
      this.username = localStorage.getItem('username') || '';
    },
  }
}
</script>

<style scoped>
.admin-header {
  background-color: #fff; /*rgba(42, 130, 148)#fff*/
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0 20px;
  height: 67px;
  position: sticky;
  top: 0;
  z-index: 999;
}

.admin-user-info {
  display: flex;
  align-items: center;
}

.username {
  margin: 0 5px;
  color: #333;
  text-decoration: none;
  font-weight: 500;
}

.username:hover {
  color: #409EFF;
  text-decoration: underline;
}

.login-tip {
  color: #909399;
  margin-left: 5px;
}

.el-button {
  padding: 0;
  margin-left: 10px;
}
</style>
